<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/styletable.css" type="text/css"/>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/layui.all.js" charset="utf-8"></script>
    <script src="/js/jquery.2.1.4.js" charset="utf-8"></script>
</head>
<body>
<script>
    function urg() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#checkform").attr("action", "/prob/urg").submit();
        }
    }

    function fine() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#checkform").attr("action", "/prob/fine").submit();
        }
    }

    function end() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#checkform").attr("action", "/prob/end").submit();
        }
    }

    function dele() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#checkform").attr("action", "/prob/del").submit();
        }
    }

    function reply(th) {
        var message = '<div style="margin: 0px" class="layui-input-block">\n' +
            '            <textarea id="textcontent" rows="7" cols="15" style="margin: 0px 5px 0px 5px;" name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>\n' +
            '          </div>';
        var pid = $(th).parent().prevAll(".pid").children().val();
        layer.open({
            title: '回复内容'
            , area: ['45%', '50%']
            , content: message
            , yes: function (index, layero) {
                var text = $("#textcontent").val();
                text0 = text.split("\n").join("<br>");
                if (text0.length != 0) {
                    window.location.href = "/prob/reply/" + pid + "/" + text0;
                }
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
        return false
    }

    function detail(th) {
        var prob;
        var pid = $(th).parent().prevAll(".pid").children().val();
        var ptitle = $(th).parent().prevAll(".ptitle").children().next().html();
        layer.open({
            title: ptitle,
            type: 2,
            area: ['85%', '85%'],
            content: '/prob/detail/' + pid
        });
        return false;
    }

    function dis() {
        var message = '<label for="sel">分发给：</label>\n' +
            '<select id="sel" name="selval" style="width: 150px;height: 25px">\n' +
            '<c:forEach items="${rolename}" var="rname">\n' +
            '\t<option>${rname}</option>\n' +
            '</c:forEach>\n' +
            '</select>';
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            layer.open({
                title: '分发问题'
                , content: message
                , yes: function (index, layero) {
                    $("#checkform").attr("action", "/prob/editRole/" + $("#sel  option:selected").text()).submit();
                    layer.close(index);
                }
            });
        }
    }
</script>
<div style="margin: 10px 15px 0px 15px">
    <div style="margin-top: 1px;margin-left: 1px;margin-bottom: 8px">
        <button class="layui-btn layui-btn-warm" onclick="dele();">删除</button>
        <button class="layui-btn layui-btn-danger" onclick="urg();">加急</button>
        <a class="layui-btn layui-btn-normal" href="javascript:void(0);" onclick="dis();">分发</a>
        <button class="layui-btn layui-btn-edit" onclick="fine();">精选</button>
        <button class="layui-btn layui-btn-delete" onclick="end();">结束</button>
    </div>
    <form id="checkform">
        <table style="width: 100%">
            <tr>
                <th width="5%"></th>
                <th width="35%">标题</th>
                <th width="15%">创建时间</th>
                <th width="10%">状态</th>
                <th width="15%">是否精选</th>
                <th width="20%">操作</th>
            </tr>

            <c:forEach items="${probs}" var="prob">
                <tr>
                    <td class="pid" align="center"><input class="check" name="checks" value="${prob.pid}" type="checkbox"/></td>
                    <td class="ptitle">
                        <c:if test="${prob.purg=='紧急'}">
                        <span class="layui-btn layui-btn-mini layui-btn-danger">紧急</span>
                        <span>${prob.ptitle}</span></td>
                    </c:if>
                    <c:if test="${'紧急'!= prob.purg}">
                        <span></span>
                        <span>${prob.ptitle}</span></td>
                    </c:if>
                    <td>${prob.pdate}</td>
                    <td align="center"><span class="layui-btn layui-btn-mini
                    <c:if test="${prob.pstate=='进行中'}"> layui-btn-role</c:if>
                    <c:if test="${prob.pstate=='已结束'}"> layui-btn-warm</c:if>">${prob.pstate}</span>
                    </td>
                    <td align="center"><span class="layui-btn layui-btn-mini
                    <c:if test="${prob.pfine=='未加精'}"> layui-btn-role</c:if>
                    <c:if test="${prob.pfine=='已加精'}"> layui-btn-warm</c:if>">${prob.pfine}</span>
                    </td>
                    <td align="center">
                        <button class="layui-btn layui-btn-small layui-btn-delete" onclick="return detail(this);">查看详情
                        </button>&nbsp;
                            <%--<a class="layui-btn layui-btn-small layui-btn-delete" href="/prob/detail">查看详情</a>&nbsp;--%>
                        <button class="layui-btn layui-btn-small layui-btn-append" onclick="return reply(this);">回复
                        </button>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>
</div>
</body>
</html>
